package me.jessyan.mvparms.demo.mvp.ui.activity.account;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.jess.arms.widget.CustomPopupWindow;

import javax.inject.Inject;
import javax.inject.Named;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import me.jessyan.mvparms.demo.R;
import me.jessyan.mvparms.demo.di.component.account.DaggerAccountManageComponent;
import me.jessyan.mvparms.demo.di.module.account.AccountManageModule;
import me.jessyan.mvparms.demo.mvp.contract.account.AccountManageContract;
import me.jessyan.mvparms.demo.mvp.presenter.account.AccountManagePresenter;
import me.jessyan.mvparms.demo.mvp.ui.widget.CustomToolbar;

import static com.jess.arms.utils.Preconditions.checkNotNull;


/**
 * 账号管理
 */
public class AccountManageActivity extends BaseActivity<AccountManagePresenter> implements AccountManageContract.View {

    @BindView(R.id.toolbar)
    CustomToolbar toolbar;

    @Inject
    @Named("unBindPop")
    CustomPopupWindow unBindPop;
    @BindView(R.id.change_phone_tv)
    TextView changePhoneTv;
    @BindView(R.id.password)
    TextView password;
    @BindView(R.id.three_bind)
    TextView threeBind;
    @BindView(R.id.weichat)
    TextView weichat;


    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerAccountManageComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .accountManageModule(new AccountManageModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_account_manage; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        toolbar.setListener(new CustomToolbar.ToolbarListener() {
            @Override
            public void onLeftBack() {
                killMyself();
            }

            @Override
            public void onRightBack() {

            }
        });
        unBindPop.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                backgroundAlpha(1);
            }
        });
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }


    @Override
    public AccountManageActivity getActivity() {
        return this;
    }

    @Override
    public void dismissPop() {
        if (unBindPop != null && unBindPop.isShowing()) {
            unBindPop.dismiss();
        }
    }

    @Override
    public void popBackSureBind() {
        showMessage("确定");
    }



    @OnClick({R.id.change_phone_tv, R.id.change_pass_tv, R.id.unbind_tv})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.change_phone_tv:
                startActivity(new Intent(this,ChangePhoneActivity.class));
                break;
            case R.id.change_pass_tv:
                startActivity(new Intent(this,SmsVeriftyActivity.class));
                break;
            case R.id.unbind_tv:
                unBindPop.show();
                backgroundAlpha(0.7f);
                break;
        }
    }
}
